#!/bin/bash
#pMusic
#GPL - Copyright Sigmund Berglund

export LC_ALL=C
TMP="`ps -eo pid,command`"

killme(){
	for I in `echo "$TMP" | grep -F "$1" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
}

case $1 in
-trackinfo) #user is writing in a id3tag <entry>, and we want to avoid a refresh that would reset content of <entry>
	killme func_trackinfo
	;;
-audio) #interupt playing (ie. when moving progressbar or jump to time) - we don't want to save rating
	echo true > $WORKDIR/NO_RATING
	killme aplay
	for I in `echo "$TMP" | grep -F "ffmpeg" | grep -F 'f au ' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killme 'func_player -playing'
	for I in `echo "$TMP" | grep -F "streamripper" | grep -F "A -k 0 -u WinampMPEG/5.0 -r 8002" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killall cdda2wav 2> /dev/null
	;;
*)
	killme func_trackinfo
	killme 'func -read_cd'
	killme aplay
	killme ffplay
	for I in `echo "$TMP" | grep -F "ffmpeg" | grep -F 'f au ' | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killme 'func_player -playing'
	for I in `echo "$TMP" | grep -F "streamripper" | grep -F "A -k 0 -u WinampMPEG/5.0 -r 8002" | awk '{print $1}'`; do kill -9 $I 2> /dev/null; done
	killall cdda2wav 2> /dev/null
	;;
esac

